package com.yiren.backstage.judge.handler;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.yiren.backstage.currency.constant.AutoJudgeConstant;
import com.yiren.backstage.currency.entity.GradeStandardEntity;
import com.yiren.backstage.currency.entity.ProjectEntity;
import com.yiren.backstage.currency.enums.TaskStateEnum;
import com.yiren.backstage.judge.api.IExamStateCallBack;
import com.yiren.backstage.judge.services.standard.IAutoJudgeHandlerService;
import com.yiren.backstage.judge.services.standard.impl.AutoJudgeHandlerServiceImpl;
import com.yiren.backstage.judge.thread.AutoJudgeThread;

/**
 * Time:2021/11/09 15:41
 * Author:xiaozan
 * Description:自动评判 消息处理中心
 */
public class AutoJudgeHandler extends Handler  {

    private IAutoJudgeHandlerService autoJudgeHandlerService;

    private IExamStateCallBack iExamStateCallBack;

    private TaskStateEnum taskStateEnum;

    public AutoJudgeHandler(Context context,IExamStateCallBack iExamStateCallBack){
        autoJudgeHandlerService = new AutoJudgeHandlerServiceImpl(context,this);
        this.iExamStateCallBack = iExamStateCallBack;
    };

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what){
            case AutoJudgeConstant.PLAY_PROJECT_START_VOICE://播报项目开始语音
                autoJudgeHandlerService.playProjectStartVoice((ProjectEntity) msg.obj);
                break;
            case AutoJudgeConstant.START_PROJECT_JUDGE://启动项目评判（启动父级编号为0的）
                autoJudgeHandlerService.startProjectJudge((ProjectEntity) msg.obj);
                break;
            case AutoJudgeConstant.START_WHOLE_COURSE_PROJECT_JUDGE://启动全程评判项目
                autoJudgeHandlerService.startWholeCourseProjectJudge((ProjectEntity) msg.obj);
                break;
            case AutoJudgeConstant.AGAIN_EXECUTE_JUDGE://重新执行评判
                autoJudgeHandlerService.againExecuteJudge((AutoJudgeThread) msg.obj);
                break;
            case AutoJudgeConstant.CONTINUE_EXECUTE://继续执行
                autoJudgeHandlerService.continueExecuteJudge((AutoJudgeThread) msg.obj);
                break;
            case AutoJudgeConstant.ADD_PROJECT_GRADE://增加扣分
                //将扣分增加到扣分集合中
                autoJudgeHandlerService.addGradeStandard((GradeStandardEntity)msg.obj);
                break;
            case AutoJudgeConstant.PLAY_PROJECT_END_VOICE://播报项目结束语音
                autoJudgeHandlerService.playProjectEndVoice((ProjectEntity) msg.obj);
                break;
            case AutoJudgeConstant.AUTO_END_EXAM:
                iExamStateCallBack.endExam();
                break;
        }
    }

    public TaskStateEnum getTaskStateEnum() {
        return taskStateEnum;
    }

    public void setTaskStateEnum(TaskStateEnum taskStateEnum) {
        this.taskStateEnum = taskStateEnum;
    }

    public IExamStateCallBack getiExamStateCallBack() {
        return iExamStateCallBack;
    }
}
